<html>
<head><meta charset="utf-8"><title>Testing proc macros · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Testing.20proc.20macros.html">Testing proc macros</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225064915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Testing%20proc%20macros/near/225064915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ethan Brierley <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Testing.20proc.20macros.html#225064915">(Feb 03 2021 at 19:06)</a>:</h4>
<p>I am trying to add a bare minimum proc macro to <code>rustc_marcros</code> to later grow into something larger if I can work it all out. I am quite new to writing proc macros.</p>
<p>How are proc macros generally tested in the compiler? I was thinking of creating a module and running <code>cargo-expand</code> against it just to see the macro in action but am thinking there is probably a better way.</p>



<a name="225157252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Testing%20proc%20macros/near/225157252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ethan Brierley <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Testing.20proc.20macros.html#225157252">(Feb 04 2021 at 13:17)</a>:</h4>
<p>I made a little helper function to <code>assert_eq</code> <code>TokenStream</code>s after converting them to <code>String</code>s and am happy with that.</p>



<a name="225183835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Testing%20proc%20macros/near/225183835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Julian-Wollersberger <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Testing.20proc.20macros.html#225183835">(Feb 04 2021 at 16:25)</a>:</h4>
<p>The proc macro for the query definitions doesn't have any tests itself. It's tested by seeing if the compiler compiles and if the test suit runs.<br>
I don't know about others in <code>rustc_macro</code>, but unit tests with <code>#[test]</code> are overall rare in <code>rustc</code>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>